package com.itheima.demo.vo;



import lombok.Data;

/**
 * 后端往前端返回数据的时候的通用格式
 * */
@Data
public class Result {

    /**
     * 0 失败
     * 1 成功
     * */
    private Integer code;

    private String msg;

    private Object data;

    /**
     * 成功时候的返回
     * */
    public static Result ok(){
        Result result = new Result();
        result.setCode(1);
        return result;
    }

    /**
     * 成功时候的返回
     * */
    public static Result ok(Object data){
        Result result = new Result();
        result.setCode(1);
        result.setData(data);
        return result;
    }

    /**
     * 失败时候的返回
     * */
    public static Result error(String msg){
        Result result = new Result();
        result.setCode(0);
        result.setMsg(msg);
        return result;
    }


}